package cn.yiyuan.auth.controller;

import cn.yiyuan.auth.entity.ShopEntity;
import cn.yiyuan.auth.service.IShopService;
import cn.yiyuan.base.until.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @user m
 * @project car_mall_system
 * @date 2023-12-28
 * @package cn.yiyuan.auth.controller
 */
@RestController
@RequestMapping("/shop")
public class ShopController {

    @Autowired
    public IShopService shopService;


    @PostMapping("/save")
    public AjaxResult addOrUpdate(@RequestBody ShopEntity shopEntity){
        try {
            if( shopEntity.getId()!=null)
                shopService.update(shopEntity);
            else
                shopService.insert(shopEntity);
            return AjaxResult.success();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("保存对象失败！"+e.getMessage());
        }
    }

    /**
     * 分页查询数据
     *
     *
     * @return PageList 分页对象
     */
//    @PostMapping
//    public AjaxResult queryPage(@RequestBody ShopQuery query)
//    {
//        try {
//            PageInfo<Shop> pageList = shopService.queryPage(query);
//            return AjaxResult.success(pageList);
//        } catch (Exception e) {
//            e.printStackTrace();
//            return AjaxResult.error("获取分页数据失败！"+e.getMessage());
//        }
//    }

    @PostMapping("/settlement")
    public AjaxResult settlement(@RequestBody ShopEntity shop){
        try {
            shopService.settlement(shop);
            return AjaxResult.success();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error(e.getMessage());
        }
    }

    @GetMapping("/active/{shopId}")
    public AjaxResult active(@PathVariable("shopId")Long shopId){
        try {
            // 修改店铺的状态=激活成功
            // 修改管理员的状态=正常
            return AjaxResult.success();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error(e.getMessage());
        }
    }

    @PostMapping("/active/{shopId}")
    public AjaxResult updataactive(@PathVariable("shopId")Long shopId){
        try {
            // 修改店铺的状态=激活成功
            shopService.updataactive(shopId);
            // 修改管理员的状态=正常
            return AjaxResult.success();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error(e.getMessage());
        }
    }


}
